package com.bw.liuyushan.zhuangao4_mvptest1.MVP.View.Activity;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.os.Handler;
import android.util.Log;
import android.view.WindowManager;
import android.widget.ImageView;

import com.blankj.utilcode.util.ToastUtils;
import com.bw.liuyushan.mvp_lib.View.BaseActivity;
import com.bw.liuyushan.zhuangao4_mvptest1.MVP.Contrack.ICTest;
import com.bw.liuyushan.zhuangao4_mvptest1.MVP.Model.BaseModelTest;
import com.bw.liuyushan.zhuangao4_mvptest1.MVP.Presenter.BasePresenterTest;
import com.bw.liuyushan.zhuangao4_mvptest1.R;
import com.bw.liuyushan.zhuangao4_mvptest1.Utils.WindowUtils;

import java.util.Timer;
import java.util.TimerTask;

/**
 * ZhuanGao4_MVPTest1
 * file name is : GuideActivity
 * created by Ender on 2021/8/11 15:31.
 * author : Liuyushan
 * Describe:引导页的Activity类 2秒自动跳转 外部类Thread和Handel实现或者属性动画的透明效果
 */
public class GuideActivity extends BaseActivity<BasePresenterTest> implements ICTest.C_ViewTest{
    private android.widget.ImageView welcome;

    @Override
    public int bindLayout() {
        return R.layout.activity_guide;
    }

    @Override
    public void initView() {
        //沉浸式布局
        WindowUtils.hideStatusBar(this);
        //防止内存泄露
        ip = new BasePresenterTest(new BaseModelTest(), this);

        welcome = (ImageView) findViewById(R.id.welcome);
    }

    @Override
    public void initDate() {
        //线程跳转 倒计时
//        Handler handler = new Handler();
//        handler.postDelayed(new Runnable() {
//            @Override
//            public void run() {
//                Timer timer = new Timer();
//                timer.schedule(new TimerTask() {
//                    @Override
//                    public void run() {
//                        Intent intent = new Intent(GuideActivity.this, MainActivity.class);
//                        startActivity(intent);
//                    }
//                },4000);
//            }
//        },0);
        //动画定时跳转 透明效果
        ObjectAnimator alpha = ObjectAnimator.ofFloat(welcome,"alpha", 0, 1);
        alpha.setDuration(2000);
        alpha.start();
        alpha.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                ToastUtils.showShort("Eason Chen欢迎你");
                Intent intent = new Intent(GuideActivity.this, MainActivity.class);
                startActivity(intent);
                //不结束 在主页面点击返回就会出现 退出到导航页无法结束
                finish();//可以清除回退栈
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });

    }
    /**
     * 当布局发生改变时候的方法
     * 沉浸式布局 工具类调用
     * @param params
     */
    @Override
    public void onWindowAttributesChanged(WindowManager.LayoutParams params) {
        super.onWindowAttributesChanged(params);
        WindowUtils.hideStatusBar(this);
    }
}

